<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增list')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sale-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">销售名称：</label>
            <div class="col-sm-8">
                <input name="sName" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">处理人：</label>
            <div class="col-sm-8">
                <select class="form-control" name="uId" id="uId" required>
                    <option value="">请选择处理人</option>
                </select>
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">客户：</label>
            <div class="col-sm-8">
                <select class="form-control" name="cId" id="cId"  required >
                    <option value="">请选择客户</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">销售时间：</label>
            <div class="col-sm-8">
                <input type="text" class="time-input"  name="saleTime" placeholder="开始时间" value="" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea class="form-control"  name="remark"  value="" ></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    function addOptions(project) {

        var pro = $('#uId');
        var options="";
        $(project).each(function() {
            options += '<option  value="' + this.userId + '" >' + this.userName + '</option>';
        });
        pro.append(options);
    }

    $(function () {
        $.ajax({
            url: prefix+"/userList",//请求地址
            type:"get" ,// 请求方式
            async:false,// 同步异步   默认true  异步
            data:{},//请求的附加数据
            timeout:1000,//请求超时时间  单位毫秒  当超时会调用error方法
            dataType:"json",//
            success:function(data){ //请求成功的回调方法
                console.log(data);
                if (data!== null) {
                    var project = data.data;
                    console.log(project)
                    addOptions(project);

                }
            },
            error:function(){
                console.log("ajax中error 方法");
            },
            complete:function(){ //当前完成就会调用  不论成功 失败
                console.log("complete 方法");
            }
        });
    })

    function addClientOptions(project) {

        var pro = $('#cId');
        var options="";
        $(project).each(function() {
            options += '<option  value="' + this.cid + '" >' + this.cname + '</option>';
        });
        pro.append(options);
    }

    $(function () {
        $.ajax({
            url: prefix+"/clientList",//请求地址
            type:"get" ,// 请求方式
            async:false,// 同步异步   默认true  异步
            data:{},//请求的附加数据
            timeout:1000,//请求超时时间  单位毫秒  当超时会调用error方法
            dataType:"json",//
            success:function(data){ //请求成功的回调方法
                console.log(data);
                if (data!== null) {
                    var project = data.data;
                    console.log(project)
                    addClientOptions(project);

                }
            },
            error:function(){
                console.log("ajax中error 方法");
            },
            complete:function(){ //当前完成就会调用  不论成功 失败
                console.log("complete 方法");
            }
        });
    })


    var prefix = ctx + "cms/sale"
    $("#form-sale-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-sale-add').serialize());
        }
    }
</script>
</body>
</html>